package org.onion.pattern.kit.springtool.converter;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.SneakyThrows;
import org.apache.commons.lang3.StringUtils;
import org.onion.pattern.kit.common.jackson.serializer.WebMvcObjectMapper;
import org.springframework.core.convert.converter.Converter;

public class String2JsonNodeConvert implements Converter<String, JsonNode> {

    private static final ObjectMapper OBJECT_MAPPER = new WebMvcObjectMapper();

    @SneakyThrows
    @Override
    public JsonNode convert(String s) {
        if (StringUtils.isBlank(s)) {
            return null;
        }

        return OBJECT_MAPPER.readTree(s);
    }

}
